﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Typheus
{
    public partial class Bookmark : Form
    {
        private Dictionary<string, string> BookMarks;
        private WebBrowser form;
        public Bookmark(string Label, string URL, WebBrowser form)
        {
            InitializeComponent();
            this.form = form;
            txtLabel.Text = Label;
            txtURL.Text = URL;
            BookMarks = ReadXML.GetBookMarkList();
            foreach (KeyValuePair<string, string> pair in BookMarks)
            {
                bookMarkList.Items.Add(pair.Key);
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                BookMarks.Add(txtLabel.Text, txtURL.Text);
                bookMarkList.Items.Add(txtLabel);
                ReadXML.AddBookMark(txtLabel.Text, txtURL.Text);
            }
            catch (Exception)
            {
                MessageBox.Show(
                    "An Error has Occured... \nThis Bookmark may already be in the list.. \ncheck it again dumbass.\n\n or it could be my terrible code.","OhShit");
            }
        }

        private void bookMarkList_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void bookMarkList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string selectedValue=bookMarkList.SelectedItem.ToString();
            form.Navigate(BookMarks[selectedValue]);
            this.Close();
        }

        private void btnGoto_Click(object sender, EventArgs e)
        {
            string selectedValue = bookMarkList.SelectedItem.ToString();
            form.Navigate(BookMarks[selectedValue]);
            this.Close();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            string selectedValue = bookMarkList.SelectedItem.ToString();
            bookMarkList.Items.Remove(bookMarkList.SelectedItem);
            BookMarks.Remove(BookMarks[selectedValue]);
            ReadXML.RemoveBookMark(selectedValue);
        }
    }
}
